package org.socialnetwork.rules;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import org.abac4j.annotations.AttributeFunction;
import org.abac4j.context.PostProcessor;
import org.socialnetwork.pojo.Photo;

public class PhotoByDescriptionChecker implements PostProcessor {
	
	@AttributeFunction
	public static boolean photoByDescription(String regex){
		return true;
	}
	
	@Override
	public Object postProcess(Object... varargs) {
		@SuppressWarnings("unchecked") List<Photo> returnList = (List<Photo>) varargs[0];
		Object[] args = (Object[]) varargs[1];
		String regex = (String) args[1];
		
		List<Photo> listaFotos = new ArrayList<Photo>();
		for(Photo photo : returnList) {
			if (Pattern.compile(regex).matcher(photo.getDescricao()).find()) {
				listaFotos.add(photo);
			}
		}
		return listaFotos;
	}
}